/*
 * =====================================================================================
 *
 *       Filename:  avl.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2014年09月25日 14时48分14秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef __AVL_H__
#define __AVL_H__

#define  LH 	(1)
#define  EH 	(0)
#define  RH 	(-1)

#define  UNBALANCE(bf) 	((bf) == 2 || (bf) == -2)

struct node_t {
	void *arg;

	int key;
	int bf;
	struct node_t *lchild, *rchild;
};

extern int hit;

#define insert_node(node, parent, key, arg)  			\
	do { 							\
		int _bf = 0; 					\
		*node == NULL; 					\
		_insert_node(node, parent, &_bf, key, arg); 	\
	} while(0)
int _insert_node(struct node_t **node, struct node_t *parent, 
	int *bf, int key, void *arg);

#define travel_node(head) _travel_node(head, 0)
void _travel_node(struct node_t *node, int height);
#endif /* __AVL_H__ */
